package com.graduate.common.shiro;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

import com.graduate.util.DigestUtils;

/**
 * shiro密码加密配置
 *
 */
public class PasswordHash implements InitializingBean {
	private String algorithmName;
	private int hashIterations;

	public String getAlgorithmName() {
		return algorithmName;
	}
	public void setAlgorithmName(String algorithmName) {
		this.algorithmName = algorithmName;
	}
	public int getHashIterations() {
		return hashIterations;
	}
	public void setHashIterations(int hashIterations) {
		this.hashIterations = hashIterations;
	}
	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.hasLength(algorithmName, "algorithmName must be MD5、SHA-1、SHA-256、SHA-384、SHA-512");
	}
	public String toHex(Object source, Object salt) {
		return DigestUtils.hashByShiro(algorithmName, source, salt, hashIterations);
	}
	
	
	public static void main(String[] args) {
		String pwd = "aa";
		String result = DigestUtils.hashByShiro("MD5", pwd, "test", 1);
		
		System.out.println(result);
		//de2ec3065687316991579e6b9e6ce143
		
		
	}
}
